home *** CD-ROM | disk | FTP | other *** search
- <?php
- /* album.php - version 1
- * .net magazine (www.netmag.co.uk), issue 83
- * Matt Kynaston, 2001
- * Distributed under the GNU Public License - www.gnu.org/copyleft/gpl.html
- *
- * This version of the PHP Photo Album displays all the images in the 'photos'
- * directory. It gives the user the opportunity to upload their own photos to
- * the album.
- */
- ?>
-
- <html>
- <head>
- <title>Photo Album</title>
- </head>
-
- <body bgcolor="#FFFFFF" text="#000000">
- <h1>PHP Photo Album</h1>
- <h3>(ugly version)</h3>
-
- <?php
- /* check to see if data has been posted to this page, and make sure it isn't blank
- * (as would happen if someone clicked the 'submit' button without first selecting
- * file).
- *
- * Note: when file is first uploaded, it's saved in a temporary directory. We must
- * copy it or it will be deleted once the viewer leaves this page
- */
- if (isset($ulFile) && $ulFile_name) {
- // copy uploaded file to photo directory
- if (copy($ulFile, "photos/$ulFile_name")) {
- print "<p>$ulFile_name successfully uploaded</p>\n";
- } else {
- // print error message if it didn't work
- print "<p>Oops! Couldn't upload $ulFile_name</p>\n";
- }
- // delete temporary file
- unlink($ulFile);
- }
- ?>
-
-
- <!-- the upload form -->
- <!-- notice how we use $PHP_SELF so uploads are sent back to this page -->
- <form name="form1" method="post" action="<?php print $PHP_SELF?>" enctype="multipart/form-data">
- <p>Add your own image to the album:<br>
- <input type="file" name="ulFile">
- </p>
- <p>
- <input type="submit" name="Submit" value="Submit">
- </p>
- </form>
-
- <p> </p>
- <table width="100%" border="0" cellspacing="10">
- <tr>
- <?php
- // this section generates table rows filled with images
- $num_cols = 4;
- $dirname = "photos";
-
- $col = 0;
- $dh = opendir( $dirname ); // open directory for reading
-
- // loop through all files in photo directory, reading filename into $file
- while($file=readdir($dh)) {
- if ($file=="." || $file=="..") continue;// ignore directory files
-
- // output table cell with image inside
- print "<td><img src='$dirname/$file'><br>$file</td>\n";
- $col++;
-
- // if max number of columns reached, start new row
- if ($col==$num_cols) {
- print "</tr>\n<tr>\n";
- $col=0;
- }
- }
-
- // fill rest of row with empty cells
- for ($i=$col;$i<=$num_cols;$i++) {
- print "<td></td>\n";
- }
- ?>
- </tr>
- </table>
-
- </body>
- </html>
-